www.gusucode.com > VC++ DES文件加密程序源码-源码程序 > VC++ DES文件加密程序源码-源码程序/code/DocEncyptDlg.cpp

    // DocEncyptDlg.cpp : implementation file
// Download by htp://www.NewXing.com

#include "stdafx.h"
#include "DocEncypt.h"
#include "DocEncyptDlg.h"
#include "stdlib.h"
#include "math.h"
#include "string.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class Encrypt :public CDialog{
public:
	static int IP_Table[64];      //初始置换(IP)
	static int E_Table[] ;//扩展变换E     
	static int S_Box[8][4][16];	//8个s盒
	static int IP_1_Table[64];//逆初始置换IP^-1
	static int P_Table[32] ;//置换运算P
	static int PC_1[56] ;  //密钥置换PC1  
	static int PC_2[48];//密钥置换PC_2
	static int move_times[16] ;       //对左移位的规定
	int K[16][48];			//存放16轮子密钥
	int c[64];				//存放明文或密文
	int L[17][32],R[17][32];  //存放加密过程中左右部分
	CString enCString;
public:
	void ToTwoBin(unsigned char p[8],int b[64])    //将字节转换成二进制流
	{
		int i,k=0;
		for(i=0;i<8;i++) 
		{
			int j=0x80;
			for(;j;j>>=1)  
			{
				if(j&p[i]) 
				{
					b[k++]=1;     
				}
				else   
				{
					b[k++]=0;   
				}
			}
		}    
	}
	void ToTow8(int a[], int b[],int n)    //八位二进制转成十进制
	{
		int i,j;
		int temp;
		int arry[8][8];
		int t=1,k;
		for(i=0;i<n/8;i++)
		{
			for(j=0;j<8;j++)
			{
				arry[i][j]=a[8*i+j];
			}
		}
		for (i=0;i<n/8;i++)
		{
			temp=0;
			for(j=7;j>=0;j--)
			{
				if(arry[i][j]==1)
				{
					t=1;
					for(k=0;k<7-j;k++)
					{
						t=t*2;
					}
					temp+=t;
				}
			}
			b[i]=temp;
		}	
	}

	void ToTwo4(int a[], int b[],int n)    //4位的二进制转十进制
	{
		int i,j;
		int temp;
		int arry[16][4];

		for(i=0;i<n/4;i++)
		{
			for(j=0;j<4;j++)
			{
				arry[i][j]=a[4*i+j];
			}
		}
		for (i=0;i<n/4;i++)
		{
			temp=arry[i][0]*8+arry[i][1]*4+arry[i][2]*2+arry[i][3]*1;
			b[i]=temp;
		}	
	}

	void Replacement(int arry1[],int arry2[],int arry3[],int num)			//置换函数,初始IP,逆初始IP。arry1[]需要置换数据, arry2[]置换函数, arry3[]转换后的,num代表多少位
	{
		int i,tmp;
		for(i=0;i<num;i++)
		{
			tmp=arry2[i];
			arry3[i]=arry1[tmp];  //按照IP的顺放置数据
		}
	}

	void Lif_move(int arry1[],int arry2[],int n)     //左移位实现函数  arry1[]需要左移的数组,arry2[]左移完后的,n左移的位数
	{
		int i;
		for(i=0;i<28;i++)
		{
			arry2[i]=arry1[(n+i)%28];
		}
	}

	void S_compress(int arry[],int shc[])	//S盒压缩变换,其中数组shc存放经过s盒的结果
	{
		int h,l;			//行,列
		int sha[8];            //存放经过s盒的十进制结果
		int i,j;
		int temp[4];

		for(i=0;i<8;i++) //s盒压缩变换
		{
			h=arry[(1+(i*6))-1]*2 + arry[(6+(i*6))-1];  //s盒接收6位的输出 将 6位输人中的第 1 位和第6位,形成一个两位二进制(0-3)作为行数
			l =arry[(2+(i*6))-1]*8 + arry[(3+(i*6))-1]*4 + arry[(4+(i*6))-1]*2 + arry[(5+(i*6))-1]; //将6位输入的中间4位构成一个二进制数(0-15)为列数
			sha[i]=S_Box[i][h][l];
		} 
		for(i=0;i<8;i++)    //8个6位数据连在一起,形成32位输出
		{
		   for(j=3;j>=0;j--)
		   {
			   temp[j]=sha[i]%2;
			   sha[i]=sha[i]/2;
		   }
		   for(j=0;j<4;j++)
		   {
			   shc[4*i+j]=temp[j];
		   }
		}
	}

	void F_Function(int a[32],int b[32],int n)	//密码函数F
	{
		int i;
		int tmp[48];
		int tep[32];
		Replacement(a,E_Table,tmp,48);			//扩展变换E
		for(i=0;i<48;i++)					//与子密钥异或
		{
			tmp[i]^= K[n][i];
		}
		S_compress(tmp,tep);              //压缩变换S
		Replacement(tep,P_Table,b,32);   //置换运算P
	}
	void SubKey(int K0[64])    //获取密钥Ki
	{
		int i;
		int K1[56],K2[56];    
		int C[17][28],D[17][28];         //置换输出的C表示前28位部分,D表示后28位部分
		Replacement(K0,PC_1,K1,56);  	//密钥置换PC_1(按PC_1上的数据顺序放置)
		for(i=0;i<28;i++)		//将PC_1输出的56比特分为左右两部分
		{
			C[0][i]=K1[i];
			D[0][i]=K1[i+28];
		}
		i=0;
		while(i<16)
		{
			int j;
			Lif_move(C[i],C[i+1],move_times[i]);   //调用左移函数
			Lif_move(D[i],D[i+1],move_times[i]);   //调用左移函数
			for(j=0;j<28;j++)
			{
				K2[j]=C[i+1][j];
				K2[j+28]=D[i+1][j];
			}
			Replacement(K2,PC_2,K[i],48);		//密钥置换PC_2 ,PC_2为压缩置换
			i++;
		}
	}

	void Anti_Key(int a[16][48])      //把解密密钥准备
	{
		int i,j;
		int tmp[16][48];
		
		for(i=0;i<16;i++)
		{
			for(j=0;j<48;j++)
			{
				tmp[i][j]=a[i][j];
			}
		}
		for(i=0;i<16;i++)  //因为解密是反过来,是用第i次迭代用17-i迭代生成的密钥月数据异或,准备异或的密钥
		{
			for(j=0;j<48;j++)
			{
				K[i][j]=tmp[15-i][j];
			}
		}

	}

	void Encryption(int m0[64],int c1[64])  //加密函数
	{
		int i,k;
		int arry[32];
		int c0[64],m1[64];
		Replacement(m0,IP_Table,m1,64);  //初始置换IP
		for(i=0;i<32;i++) 
		{
			L[0][i]=m1[i];
			R[0][i]=m1[i+32];
		}
		k=1;
		while(k<17)   //把第i-1次得到的的L和R的值作为第i次的输入数据
		{
			F_Function(R[k-1],arry,k-1);
			for(i=0;i<32;i++)
			{
				L[k][i]=R[k-1][i];
				R[k][i]=L[k-1][i]^arry[i];
			}
			k++;
		}
		for(i=0;i<32;i++)
		{
			c0[i]=R[16][i];
			c0[i+32]=L[16][i];
		}
		Replacement(c0,IP_1_Table,c1,64);   //逆初始置换
	}
	void Print()  //加密后结果输出
	{
		enCString="";
		int i;
		int p[16];
		ToTow8(c,p,64);
		for(i=0;i<8;i++)
		{	
			char s[2];
			sprintf(s,"%02X",p[i]);
			enCString+=s;
		}
	}
	bool FileEncrypt(CString filePath,CString savePath,unsigned char pwd[8])//加密文件
	{
		bool success=true;
		FILE *fp,*sp;
		savePath+="\\"+filePath.Right(filePath.GetLength()-filePath.ReverseFind('\\')-1)+".gzs";
		if((fp=fopen(filePath,"rb"))==NULL||(sp=fopen(savePath,"w+"))==NULL){
			MessageBox("打开文件失败!");
			success=false;
		}
	
		int charNumber=0;
		unsigned char fileCharArr[16];
		int pwdTwoBinArr[64];
		int fileCharTwoBinArr[64];
		ToTwoBin(pwd,pwdTwoBinArr);

		/************************************************************************/
		/*设置密码识别字符串                                                    */
		/************************************************************************/
		unsigned char pwdRegStr[8]={'t','h','l','o','f','d','l','u'};
		int pwdRegStrTwoBinArr[64];
		ToTwoBin(pwdRegStr,pwdRegStrTwoBinArr);
		SubKey(pwdTwoBinArr);
		Encryption(pwdRegStrTwoBinArr,this->c);
		this->Print();
		fputs(this->enCString,sp);

		unsigned char temp;
		int rc;
		while(success&&(rc = fread(&temp,sizeof(unsigned char), 1,fp)) != 0){
			charNumber++;
			fileCharArr[charNumber-1]=temp;
			if(charNumber==8){
				ToTwoBin(fileCharArr,fileCharTwoBinArr);
				SubKey(pwdTwoBinArr);
				Encryption(fileCharTwoBinArr,this->c);
				this->Print();
				fputs(this->enCString,sp);
				charNumber=0;
			}
		}
		if(charNumber!=0){
			unsigned char repairChar[8]={'0','0','0','0','0','0','0','0'};
			for(int i=0;i<charNumber;i++){
				repairChar[i]=fileCharArr[i];
			}
			int repeairCharTwoBin[64];
			ToTwoBin(repairChar,repeairCharTwoBin);
			SubKey(pwdTwoBinArr);
			Encryption(repeairCharTwoBin,this->c);
			this->Print();
			fputs(this->enCString,sp);
		}
		char btemp=charNumber+'0';
		unsigned char addChar[8]={btemp,btemp,btemp,btemp,btemp,btemp,btemp,btemp};
		int addCharTwoBin[64];
		ToTwoBin(addChar,addCharTwoBin);
		SubKey(pwdTwoBinArr);
		Encryption(addCharTwoBin,this->c);
		this->Print();
		fputs(this->enCString,sp);
		fclose(fp);
		fclose(sp);
		return success;
		
	}
};
int Encrypt::IP_Table[64]={
	57, 49, 41, 33, 25, 17, 9, 1,
	59, 51, 43, 35, 27, 19, 11, 3,
	61, 53, 45, 37, 29, 21, 13, 5,
	63, 55, 47, 39, 31, 23, 15, 7,
	56, 48, 40, 32, 24, 16, 8, 0,
	58, 50, 42, 34, 26, 18, 10, 2,
	60, 52, 44, 36, 28, 20, 12, 4,
	62, 54, 46, 38, 30, 22, 14, 6
};
int Encrypt::E_Table[] = {			    	//扩展变换E
	   31,  0,  1,  2,  3,  4,
		3,  4,  5,  6,  7,  8,
		7,  8, 9, 10, 11, 12,
	   11, 12, 13, 14, 15, 16,
	   15, 16, 17, 18, 19, 20,
	   19, 20, 21, 22, 23, 24,
	   23, 24, 25, 26, 27, 28,
	   27, 28, 29, 30, 31,  0
};
                                   
int Encrypt::S_Box[8][4][16]  = {												//8个s盒
					{
						{14, 4,13, 1, 2,15,11, 8, 3,10, 6,12, 5, 9, 0, 7},
						{ 0,15, 7, 4,14, 2,13, 1,10, 6,12,11, 9, 5, 3, 8},
						{ 4, 1,14, 8,13, 6, 2,11,15,12, 9, 7, 3,10, 5, 0},
						{15,12, 8, 2, 4, 9, 1, 7, 5,11, 3,14,10, 0, 6,13}
					},

					{
						{15, 1, 8,14, 6,11, 3, 4, 9, 7, 2,13,12, 0, 5,10},
						{ 3,13, 4, 7,15, 2, 8,14,12, 0, 1,10, 6, 9,11, 5},
						{ 0,14, 7,11,10, 4,13, 1, 5, 8,12, 6, 9, 3, 2,15},
						{13, 8,10, 1, 3,15, 4, 2,11, 6, 7,12, 0, 5,14, 9}
					},

					{
						{10, 0, 9,14, 6, 3,15, 5, 1,13,12, 7,11, 4, 2, 8},
						{13, 7, 0, 9, 3, 4, 6,10, 2, 8, 5,14,12,11,15, 1},
						{13, 6, 4, 9, 8,15, 3, 0,11, 1, 2,12, 5,10,14, 7},
						{ 1,10,13, 0, 6, 9, 8, 7, 4,15,14, 3,11, 5, 2,12}
					},

					{
						{ 7,13,14, 3, 0, 6, 9,10, 1, 2, 8, 5,11,12, 4,15},
						{13, 8,11, 5, 6,15, 0, 3, 4, 7, 2,12, 1,10,14, 9},
						{10, 6, 9, 0,12,11, 7,13,15, 1, 3,14, 5, 2, 8, 4},
						{ 3,15, 0, 6,10, 1,13, 8, 9, 4, 5,11,12, 7, 2,14}
					},

					{
						{ 2,12, 4, 1, 7,10,11, 6, 8, 5, 3,15,13, 0,14, 9},
						{14,11, 2,12, 4, 7,13, 1, 5, 0,15,10, 3, 9, 8, 6},
						{4, 2, 1, 11,10,13, 7, 8,15, 9,12, 5, 6, 3, 0,14},
						{11,8,12, 7, 1,14, 2,13,  6,15, 0, 9,10, 4, 5, 3}
					},

					{
						{12, 1,10,15, 9, 2, 6, 8, 0,13, 3, 4,14, 7, 5,11},
						{10,15, 4, 2, 7,12, 9, 5, 6, 1,13,14, 0,11, 3, 8},
						{ 9,14,15, 5, 2, 8,12, 3, 7, 0, 4,10, 1,13,11, 6},
						{ 4, 3, 2,12, 9, 5,15,10,11,14, 1, 7, 6, 0, 8,13}
					},

					{
						{ 4,11, 2,14,15, 0, 8,13, 3,12, 9, 7, 5,10, 6, 1},
						{13, 0,11, 7, 4, 9, 1,10,14, 3, 5,12, 2,15, 8, 6},
						{ 1, 4,11,13,12, 3, 7,14,10,15, 6, 8, 0, 5, 9, 2},
						{ 6,11,13, 8, 1, 4,10, 7, 9, 5, 0,15,14, 2, 3,12}
					},

					{
						{13, 2, 8, 4, 6,15,11, 1,10, 9, 3,14, 5, 0,12, 7},
						{ 1,15,13, 8,10, 3, 7, 4,12, 5, 6,11, 0,14, 9, 2},
						{ 7,11, 4, 1, 9,12,14, 2, 0, 6,10,13,15, 3, 5, 8},
						{ 2, 1,14, 7, 4,10, 8,13,15,12, 9, 0, 3, 5, 6,11}
					}
				};

int Encrypt::IP_1_Table[64] =						//逆初始置换IP^-1
{ 
    39, 7, 47, 15, 55, 23, 63, 31,
    38, 6, 46, 14, 54, 22, 62, 30,
    37, 5, 45, 13, 53, 21, 61, 29,
    36, 4, 44, 12, 52, 20, 60, 28,
    35, 3, 43, 11, 51, 19, 59, 27,
    34, 2, 42, 10, 50, 18, 58, 26,
    33, 1, 41, 9, 49, 17, 57, 25,
    32, 0, 40, 8, 48, 16, 56, 24
};

int Encrypt::P_Table[32] =				//置换运算P
{
	15,6,19,20,
	28,11,27,16,   
    0,14,22,25,
	4,17,30,9,   
    1,7,23,13,
	31,26,2,8,   
    18,12,29,5,
	21,10,3,24
}; 

int Encrypt::PC_1[56] =
 {
	56,48,40,32,24,16,8,   //密钥置换PC_1
    0,57,49,41,33,25,17,   
    9,1,58,50,42,34,26,   
    18,10,2,59,51,43,35,   
    62,54,46,38,30,22,14,   
    6,61,53,45,37,29,21,   
    13,5,60,52,44,36,28,   
    20,12,4,27,19,11,3
};   
  
int Encrypt::PC_2[48] =			//密钥置换PC_2
{
	13,16,10,23,0,4,
	2,27,14,5,20,9,
	22,18,11,3,25,7,
	15,6,26,19,12,1,   
    40,51,30,36,46,54,
	29,39,50,44,32,47,
	43,48,38,55,33,52,
	45,41,49,35,28,31
};  
int Encrypt::move_times[16] = {1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1};
class CAboutDlg : public CDialog
{
public:
	CAboutDlg();
	
// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};



CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDocEncyptDlg dialog

CDocEncyptDlg::CDocEncyptDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDocEncyptDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDocEncyptDlg)
	m_FilePath = _T("");
	m_FileToSavePath = _T("");
	m_PassWord = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CDocEncyptDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDocEncyptDlg)
	DDX_Control(pDX, IDC_PASSWORD, m_PasswordContrl);
	DDX_Control(pDX, IDC_ENCRYPT, m_EncryptBtn);
	DDX_Control(pDX, ID_SET_SAVE_BTN, m_SetSaveBtn);
	DDX_Control(pDX, ID_BROWSER, m_BrowserBtn);
	DDX_Text(pDX, IDC_FILE_PATH, m_FilePath);
	DDX_Text(pDX, IDC_FILE_TO_SAVE_PATH, m_FileToSavePath);
	DDX_Text(pDX, IDC_PASSWORD, m_PassWord);
	DDV_MaxChars(pDX, m_PassWord, 7);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDocEncyptDlg, CDialog)
	//{{AFX_MSG_MAP(CDocEncyptDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(ID_BROWSER, OnBrowser)
	ON_BN_CLICKED(ID_SET_SAVE_BTN, OnSetSaveBtn)
	ON_BN_CLICKED(IDC_ENCRYPT, OnEncrypt)
	ON_EN_CHANGE(IDC_PASSWORD, OnChangePassword)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDocEncyptDlg message handlers

BOOL CDocEncyptDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	m_FilePath=_T("被加密文件路径");
	m_FileToSavePath=_T("设置加密后文件保存路径");
	m_PassWord=_T("输入密匙");
	UpdateData(false);
	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CDocEncyptDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CDocEncyptDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CDocEncyptDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CDocEncyptDlg::OnBrowser() 
{
	// TODO: Add your control notification handler code here
	//文件对话框       
	CFileDialog FileDialog(true, "*.*", "", OFN_EXPLORER,  "all filds(*.*)|*.*||", this);         //显示对话框      
	if(FileDialog.DoModal() == IDOK)       
    {           
		m_FilePath = FileDialog.GetPathName();
		m_PassWord=_T("");
        m_PasswordContrl.SetReadOnly(false);
		m_PasswordContrl.SetFocus();
		UpdateData(FALSE);     
	}  
}

void CDocEncyptDlg::OnSetSaveBtn() 
{
	char szDisplayName[MAX_PATH]; // 当前文件夹名字
	char szFullPath[MAX_PATH]; // 当前文件夹路径
	BROWSEINFO bi = {0}; 
	bi.hwndOwner = NULL; 
	bi.pidlRoot = NULL; 
	bi.pszDisplayName = szDisplayName; // 注意,这里必须是一个变量,如果赋值一个字符串常量,便会出现异常,
	
	// 因为当前文件夹的名字要返回在这里。
	bi.lpszTitle = _T("请选择一个文件夹"); 
	bi.ulFlags = BIF_RETURNFSANCESTORS|BIF_RETURNONLYFSDIRS; 
	bi.lpfn = NULL; 
	bi.lParam = NULL; 
	LPITEMIDLIST lpItemIDList = ::SHBrowseForFolder(&bi);
	if(lpItemIDList != NULL)
	{
		::SHGetPathFromIDList(lpItemIDList, szFullPath);
		m_FileToSavePath=szFullPath;
		m_EncryptBtn.EnableWindow(true);
	}
	UpdateData(false);
}
/*int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData) 
{ //用于设置文件选择默认路径
	switch(uMsg){ 
	case BFFM_INITIALIZED: 
		::SendMessage(hwnd,BFFM_SETSELECTION,TRUE,(LPARAM)L"//Storage Card"); 
		break; 
	case BFFM_SELCHANGED: 
		{ 
			wchar_t curr[MAX_PATH]; 
			SHGetPathFromIDList((LPCITEMIDLIST)lParam,curr); 
			::SendMessage(hwnd,BFFM_SETSTATUSTEXT,0,(LPARAM)curr); 
		} 
		break; 
	} 
	return 0; 
} 
*/
void CDocEncyptDlg::OnEncrypt() 
{
	UpdateData(true);
	
	int pl=m_PassWord.GetLength();
	for(int i=0;i<(8-pl);i++){
		m_PassWord+="2";
	}
	unsigned char pwd[9];
	int strLength = m_PassWord.GetLength() + 1;
    strncpy((char *)pwd, m_PassWord, strLength);
	Encrypt en;
	if(en.FileEncrypt(m_FilePath,m_FileToSavePath,pwd)){
		MessageBox("文件加密成功!");
	}
	/*
	FILE *fp,*sp;
	m_FileToSavePath+="\\"+m_FilePath.Right(m_FilePath.GetLength()-m_FilePath.ReverseFind('\\')-1);
	if((fp=fopen(m_FilePath,"rb"))==NULL||(sp=fopen(m_FileToSavePath,"w+"))==NULL){
		
	}
	MessageBox(m_FileToSavePath);
	MessageBox(m_FilePath);
	unsigned char temp;
	int rc;
	int num=0;
	while((rc = fread(&temp,sizeof(unsigned char), 1,fp)) != 0&&++num<20){
		fwrite(&temp,sizeof(temp),1,sp);
	}
	fclose(fp);
	fclose(sp);
	MessageBox("ok");
	*/
}



void CDocEncyptDlg::OnChangePassword() 
{
	UpdateData(true);
	if(m_PassWord.GetLength()>0){
		m_SetSaveBtn.EnableWindow(true);
	}else{
		m_SetSaveBtn.EnableWindow(false);
		m_EncryptBtn.EnableWindow(false);
	}
}